package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     *
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * 通过用户名查询是否重名
     *
     * @param username
     * @return {@link Integer}
     */
    @Select("select count(*) from employee where username=#{username}")
    Integer selectCountByName(String username);

    /**
     * 创建员工
     *
     * @param employee
     */
    @AutoFill(OperationType.INSERT)
    void insert(Employee employee);

    /**
     * 通过姓名模糊查询
     *
     * @param name
     * @return {@link List}<{@link Employee}>
     */
    List<Employee> getEmpListByName(String name);

    /**
     * 通过id获取员工
     *
     * @param id
     * @return {@link Employee}
     */
    @Select("select id, name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user from employee where id=#{id}")
    Employee getEmpById(Long id);


    /**
     * 更新员工
     *
     * @param emp
     */
    @AutoFill(OperationType.UPDATE)
    void update(Employee emp);

    /**
     * 排除自己的查询用户名是否重名
     *
     * @param username
     * @param id
     * @return {@link Integer}
     */
    @Select("select count(*) from employee where username=#{username} and id !=#{id}")
    Integer selectCountByNameNotSelf(String username, Long id);



}
